package com.skivingcloud.report.controller;

import com.mybatisflex.core.paginate.Page;
import com.skivingcloud.admin.logutils.OperateLog;
import com.skivingcloud.common.utils.PageParameter;
import com.skivingcloud.common.utils.ReturnT;
import com.skivingcloud.common.utils.UuidUtil;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.skivingcloud.report.entity.ReportSheetPdfPrintSetting;
import com.skivingcloud.report.service.ReportSheetPdfPrintSettingService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.util.List;

/**
 * pdf/打印设置表 控制层。
 *
 * @author skivingcloud
 * @since 2024-11-07
 */
@RestController
@Tag(name = "pdf/打印设置表接口")
@RequestMapping("/reportSheetPdfPrintSetting")
public class ReportSheetPdfPrintSettingController {

    private static final Logger log = LoggerFactory.getLogger(ReportSheetPdfPrintSettingController.class);

    @Resource
    private ReportSheetPdfPrintSettingService reportSheetPdfPrintSettingService;

    /**
     * 添加pdf/打印设置表。
     *
     * @param reportSheetPdfPrintSetting pdf/打印设置表
     * @return {@code {code:0,message:"",data:true}} 添加成功，{@code {code:500,message:"",data:false}} 添加失败
     */
    @OperateLog(module="pdf/打印设置表", description = "新增pdf/打印设置表")
    @PostMapping("/save")
    @Operation(summary="保存pdf/打印设置表")
    @PreAuthorize("hasAuthority('reportSheetPdfPrintSetting:save')")
    public ReturnT<Boolean> save(@Validated @RequestBody @Parameter(description="pdf/打印设置表")ReportSheetPdfPrintSetting reportSheetPdfPrintSetting) {
        try{
            reportSheetPdfPrintSetting.setId(UuidUtil.get32UUID());
            return ReturnT.ok(reportSheetPdfPrintSettingService.save(reportSheetPdfPrintSetting));
        }catch(Exception e){
            log.error("新增pdf/打印设置表失败", e);
            return ReturnT.error("新增pdf/打印设置表失败");
        }
    }

    /**
     * 根据主键删除pdf/打印设置表。
     *
     * @param id 主键
     * @return {@code {code:0,message:"",data:true}} 删除成功，{@code {code:500,message:"",data:false}} 删除失败
     */
    @OperateLog(module="pdf/打印设置表", description = "删除pdf/打印设置表")
    @PostMapping("/remove/{id}")
    @Operation(summary="根据主键删除pdf/打印设置表")
    @PreAuthorize("hasAuthority('reportSheetPdfPrintSetting:remove')")
    public ReturnT<Boolean> remove(@PathVariable("id") @Parameter(description="pdf/打印设置表主键")Serializable id) {
        try{
            return ReturnT.ok(reportSheetPdfPrintSettingService.removeById(id));
        }catch(Exception e){
            log.error("删除pdf/打印设置表失败", e);
            return ReturnT.error("删除pdf/打印设置表失败");
        }
    }

    /**
     * 根据主键更新pdf/打印设置表。
     *
     * @param reportSheetPdfPrintSetting pdf/打印设置表
     * @return {@code {code:0,message:"",data:true}} 更新成功，{@code {code:500,message:"",data:false}} 更新失败
     */
    @OperateLog(module="pdf/打印设置表", description = "修改pdf/打印设置表")
    @PostMapping("/update")
    @Operation(summary="根据主键更新pdf/打印设置表")
    @PreAuthorize("hasAuthority('reportSheetPdfPrintSetting:update')")
    public ReturnT<Boolean> update(@Validated @RequestBody @Parameter(description="pdf/打印设置表主键")ReportSheetPdfPrintSetting reportSheetPdfPrintSetting) {
        try{
            return ReturnT.ok(reportSheetPdfPrintSettingService.updateById(reportSheetPdfPrintSetting));
        }catch(Exception e){
            log.error("保存pdf/打印设置表失败", e);
            return ReturnT.error("保存pdf/打印设置表失败！");
        }
    }

    /**
     * 根据pdf/打印设置表主键获取详细信息。
     *
     * @param id pdf/打印设置表主键
     * @return pdf/打印设置表详情
     */
    @GetMapping("/getInfo/{id}")
    @Operation(summary="根据主键获取pdf/打印设置表")
    public ReturnT<ReportSheetPdfPrintSetting> getInfo(@PathVariable("id") Serializable id) {
        return ReturnT.ok(reportSheetPdfPrintSettingService.getById(id));
    }

    /**
     * 分页查询pdf/打印设置表。
     *
     * @param parameter 分页对象
     * @return 分页对象
     */
    @PostMapping("/page")
    @Operation(summary="分页查询pdf/打印设置表")
    @PreAuthorize("hasAuthority('reportSheetPdfPrintSetting:page')")
    public ReturnT<Page<ReportSheetPdfPrintSetting>> page(@RequestBody @Parameter(description="分页信息")PageParameter<ReportSheetPdfPrintSetting> parameter) {
        Page<ReportSheetPdfPrintSetting> page = reportSheetPdfPrintSettingService.queryByPage(parameter);
        return ReturnT.ok(page);
    }

}